package com.seveneight.baijiesteward.ui.user.fragment.identify;

import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.lzy.imagepicker.ImagePicker;
import com.lzy.imagepicker.bean.ImageItem;
import com.lzy.imagepicker.ui.ImageGridActivity;
import com.seveneight.baijiesteward.R;
import com.seveneight.baijiesteward.base.BaseFragmentBack;
import com.seveneight.baijiesteward.ui.user.fragment.IdentifyFragment;
import com.seveneight.baijiesteward.utils.GlideLoader;
import com.seveneight.baijiesteward.utils.PicassoImageLoader;

import java.util.ArrayList;

/**
 * Created by user1 on 2018/2/23.
 */

public class IdentifyFragment3 extends BaseFragmentBack implements View.OnClickListener {


    private ImageView iv_step3;
    private ImagePicker imagePicker;
    private ArrayList<ImageItem> images = null;
    private String path;
    private EditText et_email;
    private EditText et_address;

    @Override
    protected int getContentView() {
        return R.layout.identify3;
    }

    @Override
    protected void initView() {
        setSwipeBackEnable(false);
        iv_step3 = findView(R.id.iv_step3);
        et_email = findView(R.id.et_email);
        et_address = findView(R.id.et_address);
    }

    @Override
    protected void initData() {
        imagePicker = ImagePicker.getInstance();
        imagePicker.setImageLoader(new PicassoImageLoader());
        imagePicker.setShowCamera(true);
        imagePicker.setMultiMode(false);
        imagePicker.setCrop(false);
        imagePicker.setSaveRectangle(true);
    }

    @Override
    protected void setListener() {
        iv_step3.setOnClickListener(this);
        et_email.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                IdentifyFragment.EMAIL = et_email.getText().toString();
            }
        });
        et_address.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                IdentifyFragment.ADDRESS = et_address.getText().toString();
            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null && requestCode == 100) {
            images = (ArrayList<ImageItem>) data.getSerializableExtra(ImagePicker.EXTRA_RESULT_ITEMS);
            path = images.get(0).path;
            IdentifyFragment.IMGSPATH3 = path;
            IdentifyFragment.STEP = 6;
            GlideLoader.displayImg(mContext, path, iv_step3);
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_step3:
                Intent intent = new Intent(mContext, ImageGridActivity.class);
                intent.putExtra(ImageGridActivity.EXTRAS_IMAGES, images);
                startActivityForResult(intent, 100);
                break;
        }
    }
}
